import java.util.Arrays;
import java.util.Scanner;

public class demo01 {
    //连号区间数
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        int count=0;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int[] nums=Arrays.copyOf(arr,n);
                Arrays.sort(nums,i,j+1);
                boolean flag=true;
                for (int k = i; k < j; k++) {
                    if(nums[k+1]-nums[k]!=1){
                        flag=false;
                    }
                }
                if(flag){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
